let app = require('./app');
let path = require('path');
let {historyApiFallback} = require('koa2-connect-history-api-fallback');
let routers = require('./routes/router-config');

let whiteList = routers.filter(item => item.url).map(item => item.url);
app.use(historyApiFallback({whiteList}));//中间件是 变量 对象 函数

// 中间件
let koaStatic = require('koa-static');
app.use(koaStatic(path.join(__dirname, './public')));
// let KoaRouter = require('koa-router');
let requestTimeMiddleware = require('./middleware/time_log.js');
let bodyParser = require('koa-bodyparser');


let router = require('./routes');


app.use(bodyParser());

// 中间件
app.use(router.routes()).use(router.allowedMethods());

app.use(requestTimeMiddleware);

const port = 3000;

app.listen(port, () => {
  console.log(`服务已启动 端口号是${port}`)
});
